<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:include="base/head::head"/>
<!--账号信息管理-->
<body>
<div th:replace="base/load::load"/>
<div id="table-tool">
    <a id="btn-add" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="onOpenAddDialog()">新增</a>
    <a id="btn-edit" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="onOpenEditDialog()">修改</a>
    <a id="btn-remove" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="onRemove()">删除</a>
    <a id="btn-refresh" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-refresh',plain:true" onclick="onRefresh()">刷新</a>
    <a id="btn-user-role" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-link',plain:true" onclick="onOpenRoleDialog()">关联角色</a>
    <a id="btn-reset-pwd" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reset-pwd',plain:true" onclick="onOpenResetPwdDialog()">重置密码</a>
</div>
<table id="table" class="easyui-datagrid" data-options="url:'page',method:'get',pagination:true,pageSize:30,pageList:[30,40,50],fit:true,singleSelect:true,fitColumns:false,scrollbarSize:0,toolbar:'#table-tool'">
    <thead>
    <tr>
        <th data-options="field:'id',align:'center',width:100">序号</th>
        <th data-options="field:'loginName',align:'center',width:100">登录名称</th>
        <th data-options="field:'loginPwd',align:'center',width:100">登录密码</th>
        <th data-options="field:'salt',align:'center',width:100">密码盐</th>
        <th data-options="field:'status',align:'center',width:100">状态</th>
        <th data-options="field:'lastTime',align:'center',width:100">最近访问时间</th>
        <th data-options="field:'sessionId',align:'center',width:100">最近会话标识</th>
    </tr>
    </thead>
</table>
<!--弹出框-->
<div id="dialog" class="easyui-dialog uq_dialog" data-options="title:'操作',modal:true,closed:true,buttons:'#dialog-tool'">
    <form id="form" method="post">
        <table>
            <tr>
                <td>登录名称:</td>
                <td>
                    <input id="id" name="id" type="hidden"/>
                    <input name="loginName" class="easyui-textbox" style="width: 200px" data-options="required:true"/></td>
                <td>登录密码:</td>
                <td><input name="loginPwd" class="easyui-textbox" style="width: 200px" data-options="required:true"/></td>
            </tr>
            <tr>
                <td>状态:</td>
                <td>
                    <select name="status" class="easyui-combobox" style="width: 200px" data-options="value:0,panelHeight:'auto',required:true">
                        <option value="0">正常</option>
                        <option value="1">禁用</option>
                    </select>
                </td>
                <td>隶属部门:</td>
                <td><input name="deptId" class="easyui-combotreegrid" style="width: 200px" data-options="url:'../dept/tree',method:'get',required:true,
                    idField:'id',treeField:'deptName',width:'100%',panelWidth:200,panelHeight:300,columns:[[
                    {field:'deptName',title:'部门名称',width:200}
                    ]]"/>
                </td>
            </tr>
            <tr>
                <td>显示顺序:</td>
                <td><input name="showOrder" class="easyui-numberspinner" style="width: 200px" data-options="min:0,required:true"/></td>
            </tr>
        </table>
    </form>
</div>
<div id="dialog-tool">
    <a id="dialog-save" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="onSave()">保存</a>
    <a id="dialog-close" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-close'" onclick="javascript:$('#dialog').dialog('close')">关闭</a>
</div>

<!--弹出框-->
<div id="dialog-role" class="easyui-dialog uq_dialog" data-options="title:'关联角色',modal:true,closed:true,buttons:'#dialog-role-tool'">
    <form id="form-role" method="post">
        <table>
            <tr>
                <td>角色列表:</td>
                <td>
                    <input name="uid" type="hidden"/>
                    <select id="rids" name="rids" class="easyui-combobox" style="width: 200px" data-options="url:'../role/list',valueField:'id',textField:'roleDisplay',method:'get',multiple:true,panelHeight:'auto',required:true"/>
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="dialog-role-tool">
    <a id="dialog-role-save" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="onSaveUserRole()">保存</a>
    <a id="dialog-role-close" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-close'" onclick="javascript:$('#dialog-role').dialog('close')">关闭</a>
</div>

<!--弹出框-->
<div id="dialog-pwd" class="easyui-dialog uq_dialog" data-options="title:'重置密码',modal:true,closed:true,buttons:'#dialog-pwd-tool'">
    <form id="form-pwd" method="post">
        <table>
            <tr>
                <td>旧的密码:</td>
                <td>
                    <input name="uid" type="hidden"/>
                    <input class="easyui-textbox" style="width: 200px" data-options="required:true"/>
                </td>
            </tr>
            <tr>
                <td>新的密码:</td>
                <td>
                    <input class="easyui-textbox" style="width: 200px" data-options="required:true"/>
                </td>
            </tr>
            <tr>
                <td>确认密码:</td>
                <td>
                    <input class="easyui-textbox" style="width: 200px" data-options="required:true"/>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="color: #FF0000; text-align: center;">
                    默认密码为6个1
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="dialog-pwd-tool">
    <a id="dialog-pwd-save" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="onResetPwd()">重置</a>
    <a id="dialog-pwd-close" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-close'" onclick="javascript:$('#dialog-pwd').dialog('close')">关闭</a>
</div>

<script type="text/javascript" th:src="@{/utils/System.js}"></script>
<script type="text/javascript">
    function onOpenRoleDialog() {

        var rows = $("#table").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            AlertUtil.warning("请选择后，再操作！");
            return;
        }
        if (rows.length != 1) {
            AlertUtil.warning("每次只能操作一条数据！");
            return;
        }
        var row = rows[0];
        $("#form-role input[name=uid]").val(row.id)
        $("#dialog-role").dialog("open");
        findByUid(row.id);
    }

    function findByUid(uid) {
        AjaxUtil.get("../userrole/findByUid?uid=" + uid, function (data) {
            $("#rids").combobox("setValues", data);
        });
    }

    // 保存角色与用户关联
    function onSaveUserRole() {

        $("#form-role").ajaxForm({
            "url": "ur",
            "method": "post",
            "dataType": "json",
            "beforeSubmit": function () {
                return $("#form-role").form("validate");
            },
            "success": function (data) {
                AlertUtil.info(data.msg)
                if (data.code == 1) {
                    $("#dialog-role").dialog("close");
                }
            }

        }).submit();


    }

    // 重置密码
    function onOpenResetPwdDialog() {
        $("#dialog-pwd").dialog("open");
    }

    function onResetPwd() {

    }
</script>
</body>
</html>